<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <h3>mixins</h3>
        <h5>
            {{ val }}
        </h5>
        <button @click="btn">点我</button>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>

    <script>
        const mixin1 = {
            data: {
                val: 888
            },
            created() {
                console.log('我是Mixins里面的created')
            },
            methods: {
                btn() {
                    alert(11)
                }
            },
        }

        const mixin2 = {
            data: {
                val: 999
            },
            created() {
                console.log('我是Mixins2里面的created')
            },
        }

        val = 888
        val = 999

        // 使用时  mixins  同名 实例内部的优先
        // 生命周期比较特殊
        const app = new Vue({
            el: "#app",
            data: {
                val: 1000
            },
            created() {
                console.log('我是实例里面的created')
            },
            mixins: [mixin1, mixin2]
        })


        // const obj1 = {
        //     name: "张三"
        // }

        // const obj4 = {
        //     name: "李四"
        // }

        // const obj2 = {
        //     age: 20
        // }

        // const obj3 = {
        //     sex: "男"
        // }

        // Object.assign(...)  对象合并
        // console.log(Object.assign(obj1, obj2, obj3))
        // console.log(Object.assign(obj1, obj4))
    </script>
</body>
</html>